package name.fowler.refactoring.simplestore.domain;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQueries({
	@NamedQuery(name="Customer.findAll", query="SELECT c FROM Customer c"),
	@NamedQuery(name="Customer.findByName", query="SELECT c FROM Customer c WHERE c.name = :name")
})
public class Customer extends JPAEntity {

    private String name;
    
    @OneToMany(cascade=CascadeType.ALL) 
    private List<Rental> rentals;

    public Customer() {
    	this.rentals = new LinkedList<Rental>();
    }
    
    public Customer(String name) {
        this.setName(name);
        this.rentals = new LinkedList<Rental>();
    }

    public String getName() {
        return name;
    }

    public List<Rental> getRentals() {
        return rentals;
    }

    public void addRental(Rental rental) {
        rentals.add(rental);
    }

	public void setName(String name) {
		this.name = name;
	}
}
